﻿$G.popup = {
	current: undefined,
	defaultOptions: { dismissible: false,  y: 0 },
	initialize: function() {
		$('div[data-role=popup]').on("popupafterclose", function () {
			$G.popup.current = undefined;
		});
	},
	open: function (panel, options) {
		$G.popup.current = panel;
		$(panel).popup($G.popup.defaultOptions);
		if (options)
			$(panel).popup(options);

		$(panel).popup('open');
	},
	close: function () {
		var ret = $G.popup.isOpen();
		if (ret) {
			$($G.popup.current).popup('close');
		}
		return ret;
	},
	isOpen: function () {
		return $G.popup.current != undefined;
	},
	init: function (panel, popupbeforeposition, popupafteropen) {

		if (typeof popupbeforeposition !== 'undefined') {
			$(panel).on("popupbeforeposition", function (e, ui) {
				popupbeforeposition();
			});
		}

		if (typeof popupafteropen !== 'undefined') {
			$(panel).on("popupafteropen", function (e, ui) {
				popupafteropen();
			});
		}
	}
}